import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextPane;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JTextArea;
import javax.swing.JList;
import javax.swing.JPasswordField;
import javax.swing.AbstractListModel;
import javax.swing.ListSelectionModel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;


public class GUIAppWindow {
	
	String serverIP = "128.61.20.115";
	ClientSender sendToClient = new ClientSender(serverIP);

	public JFrame frame;
	private JPanel panel;
	private JTextField txtLastName;
	private JTextField txtFirstName;
	private JTextField txtLastName_1;
	private JTextField txtDateOfBirth;
	private JTextField txtAge;
	private JTextField txtHeight;
	private JTextField txtWeight;
	private JTextField txtReasonForAppointment;
	private JTextField txtPrimaryDoctor;
	private JTextField txtTimeexpm;
	private JTextField txtYear;
	private JTextField textField_4;
	private JTextField txtStreetAddress;
	private JTextField txtCityStateZip;
	private JPasswordField txtPassword;
	private JTable table;
	//private JPanel panel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
					GUIAppWindow window = new GUIAppWindow();
					window.frame.setVisible(true);
	}

	/**
	 * Create the application.
	 */
	public GUIAppWindow() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBackground(Color.LIGHT_GRAY);
		frame.setBounds(100, 100, 640, 480);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//frame.getContentPane().setLayout(null);
		
		panel = new JPanel();
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		//INITIAL PANEL
		
		initLoginPanel();
		
	}	
	
	/**
	 * LAUNCH LOGIN PANEL
	 */
	
	public void initLoginPanel(){
			panel.removeAll();
			panel.setLayout(null);
			//panel.removeAll();
			
			JLabel lblNewLabel = new JLabel("Welcome! Insert your Username and Password:");
			lblNewLabel.setBounds(172, 11, 300, 14);
			panel.add(lblNewLabel);
			
			final JTextField txtUsername = new JTextField();
			txtUsername.addMouseListener(new MouseAdapter() {
				@Override
				public void mousePressed(MouseEvent arg0) {
					if(txtUsername.getText().equals("Username")){
						txtUsername.setText("");
					}
				}
			});
			txtUsername.setBounds(219, 34, 130, 20);
			panel.add(txtUsername);
			txtUsername.setText("Username");
			txtUsername.setColumns(10);
			
			JButton btnLogin = new JButton("Login");
			btnLogin.setBounds(239, 131, 92, 23);
			panel.add(btnLogin);
			
			JButton btnNewUser = new JButton("New User");
			btnNewUser.setBounds(226, 165, 118, 23);
			panel.add(btnNewUser);
			
			txtPassword = new JPasswordField();
			txtPassword.setText("Password");
			txtPassword.setBounds(219, 65, 130, 23);
			panel.add(txtPassword);

			
			btnNewUser.addMouseListener(new MouseAdapter() {
				@Override
				public void mousePressed(MouseEvent arg0) {
					
					//INSERT NEW USER BUTTON PRESSED CODE ACTION!
					
					initNewUserPanel();
					
					
				}
			});
			
			btnLogin.addMouseListener(new MouseAdapter() {
				@Override
				public void mousePressed(MouseEvent arg0) {
					
					//PLACE CODE FOR WHAT GUI SHOULD DO WHEN LOGIN PRESSED
					
					String username = txtUsername.getText();
					String password = txtPassword.getText();
					username = username.replace(" ", "_");
					password = password.replace(" ", "_");
					
					
					sendToClient.send("sndlogin "+username+" "+password);
					
					String answer = "0";
					while(answer.equals("0")){
						answer = sendToClient.read();
					}
					if(answer.equals("-1")){
						
						JLabel lblIncorrectUserpassword = new JLabel("Incorrect User/Password!");
						lblIncorrectUserpassword.setBounds(219, 99, 258, 14);
						panel.add(lblIncorrectUserpassword);
						
						panel.revalidate();
						panel.repaint();
						
						System.out.print("NOT VALID USER/PASSWORD!");
						//initLoginPanel();
					}
					else{
						//IF USER LOGIN IS VERIFIED... ACTIONS TAKEN
						
						
						System.out.print("USER ID RECIEVED!");
						
						//CHOOSE WHICH TYPE OF PANEL TO INITIATE BASED ON ID PRIVILEGES
						
						String returnArray[] = answer.split(" ");
						String numId = returnArray[0];
						String userType = returnArray[1];
						
						if (userType.equals("0")){
							initPatientPanel(numId);
							System.out.print(numId);
						}
						if (userType.equals("1")){
							initNursePanel();
							System.out.print(numId);
						}
						if (userType.equals("2")){
							initDoctorPanel();
							System.out.print(numId);
						}
						if (userType.equals("3")){
							initAdminPanel();
							System.out.print(numId);
						}
					
					}
				}
			});
			
			panel.revalidate();
			panel.repaint();
		}
	
	/**
	 * LAUNCH NEW USER PANEL
	 */
	
	public void initNewUserPanel(){
		panel.removeAll();
		panel.setLayout(null);

		JLabel lblNewUserSignup = new JLabel("Create Account");
		lblNewUserSignup.setBounds(245, 11, 130, 40);
		panel.add(lblNewUserSignup);
		
		final JTextField txtUsername = new JTextField();
		txtUsername.setText("Username");
		txtUsername.setBounds(245, 62, 142, 20);
		panel.add(txtUsername);
		txtUsername.setColumns(10);
		
		final JTextField txtPassword = new JTextField();
		txtPassword.setText("Password");
		txtPassword.setBounds(245, 93, 142, 20);
		panel.add(txtPassword);
		txtPassword.setColumns(10);
		
		final JTextField txtFullname = new JTextField();
		txtFullname.setText("First Name");
		txtFullname.setBounds(245, 146, 142, 20);
		panel.add(txtFullname);
		txtFullname.setColumns(10);
		
		final JTextField txtPhoneNumber = new JTextField();
		txtPhoneNumber.setText("Phone Number");
		txtPhoneNumber.setBounds(245, 221, 142, 20);
		panel.add(txtPhoneNumber);
		txtPhoneNumber.setColumns(10);
		
		final JTextField txtLastName = new JTextField();
		txtLastName.setText("Last Name");
		txtLastName.setColumns(10);
		txtLastName.setBounds(245, 181, 142, 20);
		panel.add(txtLastName);
		
		JButton btnCreateAccount = new JButton("Create Account");
		
		btnCreateAccount.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				
				//INSERT NEW USER LOGIN BUTTON ACTION CODE HERE
				
				String username = txtUsername.getText();
				username = username.replace(" ", "_");
				String password = txtPassword.getText();
				password = password.replace(" ", "_");
				String firstName = txtFullname.getText();
				firstName = firstName.replace(" ", "_");
				String lastName = txtLastName.getText();
				lastName = lastName.replace(" ", "_");
				String phoneNumber = txtPhoneNumber.getText();
				phoneNumber = phoneNumber.replace(" ", "_");
				
				sendToClient.send("newusr "+username+" "+password+" "+firstName+" "+lastName+" "+phoneNumber+ " " + "0");
				System.out.print("newusr "+username+" "+password+" "+firstName+" "+lastName+" "+phoneNumber+ " " + "0");
				
				String answer = "0";
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals(-1)){
					initLoginPanel();
				}
				
				
			}
		});
		btnCreateAccount.setBounds(149, 294, 142, 28);
		panel.add(btnCreateAccount);
		
		JLabel lblFullNamefirst = new JLabel("First Name:");
		lblFullNamefirst.setBounds(162, 149, 133, 14);
		panel.add(lblFullNamefirst);
		
		JLabel lblContactPhoneNumber = new JLabel("Contact Phone Number:");
		lblContactPhoneNumber.setBounds(114, 224, 133, 14);
		panel.add(lblContactPhoneNumber);
		
		JLabel lblUsername = new JLabel("Username:");
		lblUsername.setBounds(138, 65, 97, 14);
		panel.add(lblUsername);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setBounds(138, 96, 97, 14);
		panel.add(lblPassword);
		
		JButton btnNewButton = new JButton("Login Screen");
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				initLoginPanel();
			}
		});
		btnNewButton.setBounds(330, 294, 150, 28);
		panel.add(btnNewButton);
		
		JLabel lblLastName = new JLabel("Last Name:");
		lblLastName.setBounds(162, 184, 133, 14);
		panel.add(lblLastName);
		
		
		panel.revalidate();
		panel.repaint();	
		
	}
	
	/**
	 * LAUNCH PATIENT PANEL
	 */
	
	public void initPatientPanel(String numId){
		
		final String thisId = numId;
		
		panel.removeAll();
		panel.setLayout(null);
		
		//get first name...
		
		sendToClient.send("vw_bi" + " " + thisId);
		
		String answer = "0";
		while(answer.equals("0")){
			answer = sendToClient.read();
		}		
		String returnArray[] = answer.split(" ");
		String firstName = returnArray[0];
		firstName.replace("_", " ");
		
		JLabel lblNewLabel = new JLabel("Welcome" + " " + firstName + "!");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(178, 11, 242, 14);
		panel.add(lblNewLabel);
		
		JButton btnUpdatePersonalInformation = new JButton("Update Personal Information");
		btnUpdatePersonalInformation.addMouseListener(new MouseAdapter() { 
			@Override
			public void mousePressed(MouseEvent arg0) {
					
				sendToClient.send("vw_bi" + " " + thisId);
				
				String answer = "0";
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals(-1)){
					
				initPatientPanel(thisId);
				
				String returnArray[] = answer.split(" ");
				String firstName = returnArray[0];
				String lastName = returnArray[1];
				String dateOfBirth = returnArray[2];
				String age = returnArray[3];
				String height = returnArray[4];
				String weight = returnArray[5];
				
				JLabel lblFirstName = new JLabel("First Name:");
				lblFirstName.setBounds(270, 84, 70, 14);
				panel.add(lblFirstName);
				
				JLabel lblLastName_1 = new JLabel("Last Name:");
				lblLastName_1.setBounds(270, 118, 70, 14);
				panel.add(lblLastName_1);
				
				JLabel lblDateOfBirth = new JLabel("Date of Birth:");
				lblDateOfBirth.setBounds(270, 152, 90, 14);
				panel.add(lblDateOfBirth);
				
				JLabel lblAge = new JLabel("Age:");
				lblAge.setBounds(270, 186, 70, 14);
				panel.add(lblAge);
				
				JLabel lblHeight = new JLabel("Height:");
				lblHeight.setBounds(270, 220, 70, 14);
				panel.add(lblHeight);
				
				JLabel lblWeight = new JLabel("Weight:");
				lblWeight.setBounds(270, 251, 70, 14);
				panel.add(lblWeight);
				
				txtFirstName = new JTextField();
				txtFirstName.setText(firstName);
				txtFirstName.setBounds(361, 80, 203, 20);
				panel.add(txtFirstName);
				txtFirstName.setColumns(10);
				
				txtLastName_1 = new JTextField();
				txtLastName_1.setText(lastName);
				txtLastName_1.setBounds(361, 114, 203, 20);
				panel.add(txtLastName_1);
				txtLastName_1.setColumns(10);
				
				txtDateOfBirth = new JTextField();
				txtDateOfBirth.setText(dateOfBirth);
				txtDateOfBirth.setBounds(361, 148, 102, 20);
				panel.add(txtDateOfBirth);
				txtDateOfBirth.setColumns(10);
				
				txtAge = new JTextField();
				txtAge.setText(age);
				txtAge.setBounds(361, 182, 102, 20);
				panel.add(txtAge);
				txtAge.setColumns(10);
				
				txtHeight = new JTextField();
				txtHeight.setText(height);
				txtHeight.setBounds(361, 216, 102, 20);
				panel.add(txtHeight);
				txtHeight.setColumns(10);
				
				txtWeight = new JTextField();
				txtWeight.setText(weight);
				txtWeight.setBounds(361, 247, 102, 20);
				panel.add(txtWeight);
				txtWeight.setColumns(10);
				
				JButton btnNewButton_13 = new JButton("Update");
				
				btnNewButton_13.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						String firstName = txtFirstName.getText().replace(" ", "_");
						String lastName = txtLastName_1.getText().replace(" ", "_");
						String fullName = firstName+ " " + lastName;
						String dateOfBirth = txtDateOfBirth.getText();
						String age = txtAge.getText();
						String height = txtHeight.getText();
						String weight = txtWeight.getText();
						
						dateOfBirth = dateOfBirth.replace(" ", "_");
						age = age.replace(" ", "_");
						height = height.replace(" ", "_");
						weight = weight.replace(" ", "_");
		
						sendToClient.send("edt_ptnt" + " " + thisId+" "+fullName+" "+dateOfBirth+ " " +age+" "+height+" "+weight);
						
						String answer = "no";
						
						while(answer.equals("no")){
							answer = sendToClient.read();
						}
						
						if(answer.equals("0")){
							initPatientPanel(thisId);
							System.out.print("SUCCESSFUL UPDATE");
							
							JLabel lblSuccess = new JLabel("INFORMATION UPDATED!");
							lblSuccess.setBounds(270, 84, 200, 14);
							panel.add(lblSuccess);
							panel.revalidate();
							panel.repaint();
						}
					
					}
				
				});
				btnNewButton_13.setBounds(330, 302, 136, 23);
				panel.add(btnNewButton_13);
				
				panel.revalidate();
				panel.repaint();
							
				}
			}
		});
		btnUpdatePersonalInformation.setBounds(10, 47, 185, 23);
		panel.add(btnUpdatePersonalInformation);
			
		JButton btnNewButton_1 = new JButton("Update Billing Information");
		btnNewButton_1.addMouseListener(new MouseAdapter() { 
			@Override
			public void mousePressed(MouseEvent arg0) {
				
				sendToClient.send("vw_bill" + " " + thisId);
				
				String answer = "0";
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals(-1)){
				initPatientPanel(thisId);
					
				
				String returnArray[] = answer.split(" ");
				String billing = returnArray[0];
				String creditCard = returnArray[1];
				
				billing = billing.replace("_", " ");
				
				JLabel lblNewLabel_1 = new JLabel("Update Billing Information");	
				lblNewLabel_1.setBounds(314, 51, 192, 14);
				panel.add(lblNewLabel_1);
				
				JLabel lblStreetAddress = new JLabel("Billing Address:");
				lblStreetAddress.setHorizontalAlignment(SwingConstants.RIGHT);
				lblStreetAddress.setBounds(205, 95, 130, 14);
				panel.add(lblStreetAddress);
				
				
				final JTextField txtCreditCard = new JTextField(creditCard);
				txtCreditCard.setBounds(345, 196, 192, 23);
				panel.add(txtCreditCard);
				txtCreditCard.setColumns(10);
				
				JButton btnSubmit_1 = new JButton("Submit");
				btnSubmit_1.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						
						String billingAddress = (txtStreetAddress.getText());  //+" "+txtCityStateZip.getText());
						String cardNumber = txtCreditCard.getText();
					
						billingAddress = billingAddress.replace(" ", "_");
						
						sendToClient.send("edt_bill" + " " + thisId + " " + billingAddress+" "+cardNumber);
						
						
						String answer = "no";
						
						while(answer.equals("no")){
							answer = sendToClient.read();
						}
						
						if(answer.equals("0")){
							initPatientPanel(thisId);
							System.out.print("BILLING ADDRESS CHANGE SENT");
							
							JLabel lblSuccess = new JLabel("BILLING INFORMATION CHANGE ACCEPTED!");
							lblSuccess.setBounds(270, 84, 200, 14);
							panel.add(lblSuccess);
							panel.revalidate();
							panel.repaint();
						}
						else{
							JLabel lblSuccess = new JLabel("BILLING INFORMATION CHANGE FAILED!");
							lblSuccess.setBounds(270, 84, 200, 14);
							panel.add(lblSuccess);
							panel.revalidate();
							panel.repaint();
						}
						
						
					}
				});
				btnSubmit_1.setBounds(353, 300, 89, 23);
				panel.add(btnSubmit_1);
				
				JLabel lblCreditCard = new JLabel("Credit Card Type:");
				lblCreditCard.setHorizontalAlignment(SwingConstants.RIGHT);
				lblCreditCard.setBounds(225, 162, 110, 14);
				panel.add(lblCreditCard);
				
				JComboBox comboBox = new JComboBox();
				comboBox.setModel(new DefaultComboBoxModel(new String[] {"Visa", "Mastercard", "Discover"}));
				comboBox.setBounds(345, 162, 79, 23);
				panel.add(comboBox);
				
				JLabel lblCreditCardNumber = new JLabel("Credit Card Number:");
				lblCreditCardNumber.setHorizontalAlignment(SwingConstants.RIGHT);
				lblCreditCardNumber.setBounds(213, 200, 122, 19);
				panel.add(lblCreditCardNumber);
				
				txtStreetAddress = new JTextField();
				txtStreetAddress.setText(billing);
				txtStreetAddress.setBounds(340, 92, 260, 23);
				panel.add(txtStreetAddress);
				txtStreetAddress.setColumns(10);
				
				panel.revalidate();
				panel.repaint();
				
					
				}
				
			}
		});
		btnNewButton_1.setBounds(10, 80, 185, 23);
		panel.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("Request Appointment");
		btnNewButton_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				initPatientPanel(thisId);
				
				txtReasonForAppointment = new JTextField();
				txtReasonForAppointment.setText("Reason for Appointment");
				txtReasonForAppointment.setBounds(360, 81, 175, 22);
				panel.add(txtReasonForAppointment);
				txtReasonForAppointment.setColumns(10);
				
				txtPrimaryDoctor = new JTextField();
				txtPrimaryDoctor.setText("Primary Doctor (Last Name)");
				txtPrimaryDoctor.setBounds(360, 115, 175, 22);
				panel.add(txtPrimaryDoctor);
				txtPrimaryDoctor.setColumns(10);
				
				final JComboBox timeComboBox = new JComboBox();
				timeComboBox.setModel(new DefaultComboBoxModel(new String[] {"9am", "10am", "11am", "12pm", "1pm", "2pm", "3pm", "4pm", "5pm"}));
				timeComboBox.setBounds(360, 149, 175, 23);
				panel.add(timeComboBox);
				
				final JComboBox comboBox = new JComboBox();
				comboBox.setModel(new DefaultComboBoxModel(new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}));
				comboBox.setBounds(360, 217, 175, 22);
				panel.add(comboBox);
				
				final JComboBox comboBox_1 = new JComboBox();
				comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}));
				comboBox_1.setBounds(360, 183, 53, 22);
				panel.add(comboBox_1);
				
				txtYear = new JTextField();
				txtYear.setText("Year");
				txtYear.setBounds(360, 250, 86, 20);
				panel.add(txtYear);
				txtYear.setColumns(10);
				
				JLabel lblReasonForAppointment = new JLabel("Reason for Appointment:");
				lblReasonForAppointment.setHorizontalAlignment(SwingConstants.RIGHT);
				lblReasonForAppointment.setBounds(205, 84, 145, 14);
				panel.add(lblReasonForAppointment);
				
				JLabel lblDoctor = new JLabel("Doctor:");
				lblDoctor.setHorizontalAlignment(SwingConstants.RIGHT);
				lblDoctor.setBounds(205, 118, 145, 19);
				panel.add(lblDoctor);
				
				JLabel lblTime = new JLabel("Time:");
				lblTime.setHorizontalAlignment(SwingConstants.RIGHT);
				lblTime.setBounds(215, 152, 136, 23);
				panel.add(lblTime);
				
				JLabel lblDay = new JLabel("Day:");
				lblDay.setHorizontalAlignment(SwingConstants.RIGHT);
				lblDay.setBounds(304, 186, 46, 14);
				panel.add(lblDay);
				
				JLabel lblMonth = new JLabel("Month:");
				lblMonth.setHorizontalAlignment(SwingConstants.RIGHT);
				lblMonth.setBounds(267, 220, 83, 14);
				panel.add(lblMonth);
				
				JLabel lblYear = new JLabel("Year:");
				lblYear.setHorizontalAlignment(SwingConstants.RIGHT);
				lblYear.setBounds(304, 253, 46, 14);
				panel.add(lblYear);
				
				JButton btnSubmit = new JButton("Submit");
				btnSubmit.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent arg0) {
						String month = Integer.toString(comboBox.getSelectedIndex());
						String day = (String)comboBox_1.getSelectedItem();
						int intTime = (timeComboBox.getSelectedIndex()+9);
						String stringTime = ""+intTime;
						String year = txtYear.getText();
						String doctor = txtPrimaryDoctor.getText();
						String reason = txtReasonForAppointment.getText();
						
						reason = reason.replace(" ", "_");
						doctor = doctor.replace(" ", "_");
						year = year.replace(" ", "_");
						
						sendToClient.send("rqs_appt" + " " + thisId+" "+reason+" "+doctor+ " " +stringTime+" "+day+" "+month+" "+year);
						
						String answer = "no";
						
						while(answer.equals("no")){
							answer = sendToClient.read();
						}
						
						if(answer.equals("-1")){
							
							initPatientPanel(thisId);
							JLabel lblOverload = new JLabel("APPOINTMENT ALREADY REQUESTED!");
							lblOverload.setBounds(270, 84, 250, 14);
							panel.add(lblOverload);
							panel.revalidate();
							panel.repaint();
							
						}
						
						if(answer.equals("0")){
							initPatientPanel(thisId);
							JLabel lblSuccess = new JLabel("APPOINTMENT REQUEST SENT");
							lblSuccess.setBounds(270, 84, 200, 14);
							panel.add(lblSuccess);
							panel.revalidate();
							panel.repaint();
						}
						
						answer = null;
					}
				});
				btnSubmit.setBounds(360, 317, 89, 23);
				panel.add(btnSubmit);
			}
		});
		btnNewButton_2.setBounds(10, 114, 185, 23);
		panel.add(btnNewButton_2);
			
		JButton btnNewButton_3 = new JButton("View Medical History");
		btnNewButton_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				initPatientPanel(thisId);
				
				sendToClient.send("vw_med_hist " + thisId);
				
				String answer = "0";
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				String medHistoryText = answer.replace("_", " ");
				
				JTextArea patientHistoryText = new JTextArea(medHistoryText);
				patientHistoryText.setWrapStyleWord(true);
				patientHistoryText.setLineWrap(true);
				patientHistoryText.setEditable(false);
				patientHistoryText.setBounds(255, 79, 332, 339);
				panel.add(patientHistoryText);
				
				JLabel lblNewLabel_2 = new JLabel("Patient Medical History");
				lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
				lblNewLabel_2.setBounds(303, 51, 242, 19);
				panel.add(lblNewLabel_2);
				answer = null;
				panel.revalidate();
				panel.repaint();
				
				
			}
		});
		btnNewButton_3.setBounds(10, 148, 185, 23);
		panel.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("View Doctor's Orders");
		btnNewButton_4.setBounds(10, 182, 185, 23);
		btnNewButton_4.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				initPatientPanel(thisId);
				
				sendToClient.send("vw_doc_ord " + thisId);
				
				String answer = "0";
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				if(answer.equals("-1")){
					answer = "No Current Doctor's Orders";
				}
				
				answer = answer.replace("_"," ");
				String medHistoryText = answer.replace("\t", "\n");
				
				JTextArea patientHistoryText = new JTextArea(medHistoryText);
				patientHistoryText.setWrapStyleWord(true);
				patientHistoryText.setLineWrap(true);
				patientHistoryText.setEditable(false);
				patientHistoryText.setBounds(255, 79, 332, 339);
				panel.add(patientHistoryText);
				
				JLabel lblNewLabel_2 = new JLabel("Doctor's Orders");
				lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
				lblNewLabel_2.setBounds(303, 51, 242, 19);
				panel.add(lblNewLabel_2);
				answer = null;
				panel.revalidate();
				panel.repaint();
					
			}
		});
		panel.add(btnNewButton_4);
		
		JButton btnNewButton_5 = new JButton("View Appointments");
		btnNewButton_5.setBounds(10, 216, 185, 23);
		btnNewButton_5.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				initPatientPanel(thisId);
				
				sendToClient.send("vw_appt2 " + thisId);
				
				String answer = "0";
				
				JTextArea patientHistoryText = new JTextArea();
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				if(answer.equals("-1")){
					answer = "No Upcoming Appointments";
					patientHistoryText.setText(answer);
				}
				else{
					String returnArray[] = answer.split("\t");
				
				//String medHistoryText = answer;
				
				patientHistoryText.setText("Length (min.): "+ returnArray[0] +"\nDoctor: "+returnArray[1].replace("_", " ")+"\nReason: "+returnArray[2].replace("_", " ")+"\nTime: "+returnArray[3]+", "+returnArray[4]+", "+returnArray[5]+", "+returnArray[6]+"\nUserID: "+returnArray[7]);
				}
				
				patientHistoryText.setWrapStyleWord(true);
				patientHistoryText.setLineWrap(true);
				patientHistoryText.setEditable(false);
				patientHistoryText.setBounds(255, 79, 332, 339);
				panel.add(patientHistoryText);
				
				JLabel lblNewLabel_2 = new JLabel("Upcoming Appointments");
				lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
				lblNewLabel_2.setBounds(303, 51, 242, 19);
				panel.add(lblNewLabel_2);
				
				panel.revalidate();
				panel.repaint();
					
			}
		});
		panel.add(btnNewButton_5);
		
		JButton btnViewInvoices = new JButton("View Invoice");
		btnViewInvoices.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initPatientPanel(thisId);
				
				sendToClient.send("vw_invoice " + thisId);
				
				
				String answer = "0";
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				String returnArray[] = answer.split(" ");
				
				JTextArea invoiceText = new JTextArea("Reason: "+returnArray[0].replace("_", " ")+ "\n"+ "Price: "+returnArray[1]);
				invoiceText.setWrapStyleWord(true);
				invoiceText.setLineWrap(true);
				invoiceText.setEditable(false);
				invoiceText.setBounds(255, 79, 332, 339);
				panel.add(invoiceText);
				
				JLabel lblNewLabel_2 = new JLabel("Invoice");
				lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
				lblNewLabel_2.setBounds(303, 51, 242, 19);
				panel.add(lblNewLabel_2);
				answer = "0";
				panel.revalidate();
				panel.repaint();
			
			}
		});
		btnViewInvoices.setBounds(10, 250, 185, 23);
		panel.add(btnViewInvoices);
		
		
		JButton btnNewButton_6 = new JButton("Log Out");
		btnNewButton_6.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initLoginPanel();
			}
		});
		
		btnNewButton_6.setBounds(53, 383, 126, 23);
		panel.add(btnNewButton_6);
		
		panel.revalidate();
		panel.repaint();
		
	}
	
	/**
	 * LAUNCH DOCTOR PANEL
	 */
	
	public void initDoctorPanel(){
		String answer = "0";
		panel.removeAll();
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Welcome Doctor!");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(150, 11, 269, 14);
		panel.add(lblNewLabel);
		
		JButton btnNewButton_7 = new JButton("View/Edit Patient Info");
		btnNewButton_7.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				
				initDoctorPanel();
				
				sendToClient.send("vw_users");
				
				String answer = "0";
				String[] returnArray = null;
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals("0")){
					returnArray = answer.split(" ");
					
					//txtpnCalender.setText(answer.replace("_", " "));
				}
				
				for(int i = 0; i < returnArray.length; i++){
					returnArray[i] = returnArray[i].replace("_", " ");
				}
				
				final String[] valuesArray = returnArray;
				
				final JList list = new JList();
				list.setModel(new AbstractListModel() {
					
					String[] values = valuesArray;
					//values = returnArray;
					public int getSize() {
						return values.length;
					}
					public Object getElementAt(int index) {
						return values[index];
					}
				});
				
				list.setBounds(258, 69, 170, 313);
				panel.add(list);
				
				JLabel lblUserList = new JLabel("USER LIST");
				lblUserList.setHorizontalAlignment(SwingConstants.CENTER);
				lblUserList.setBounds(258, 44, 161, 14);
				panel.add(lblUserList);
				
				
				JButton btnViewMedicalHistory = new JButton("View/Edit History");
				btnViewMedicalHistory.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						
						String selectedId = (String) list.getSelectedValue();
						int prefixEnd = selectedId.indexOf(" ");
						selectedId = selectedId.substring(0, prefixEnd);
						
						final String editedId = selectedId;
						
						initDoctorPanel();
						
						sendToClient.send("vw_med_hist " + selectedId);
						
						String answer = "0";
						
						while(answer.equals("0")){
							answer = sendToClient.read();
						}
						
						String medHistoryText = answer.replace("_"," ");
						
						final JTextArea patientHistoryText = new JTextArea(medHistoryText);
						patientHistoryText.setWrapStyleWord(true);
						patientHistoryText.setLineWrap(true);
						patientHistoryText.setEditable(true);
						patientHistoryText.setBounds(255, 79, 330, 300);
						panel.add(patientHistoryText);
						
						JLabel lblNewLabel_2 = new JLabel("Patient Medical History");
						lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
						lblNewLabel_2.setBounds(303, 51, 240, 19);
						panel.add(lblNewLabel_2);
						
						JButton btnUpdateHistory = new JButton("Update History");
						
						btnUpdateHistory.addMouseListener(new MouseAdapter() {
							@Override
							public void mousePressed(MouseEvent arg0) {
								
								sendToClient.send("edt_med_hist " + editedId +" "+ patientHistoryText.getText().replace(" ", "_"));
								initDoctorPanel();
								JLabel lblSuccess = new JLabel("PATIENT HISTORY UPDATED!");
								lblSuccess.setBounds(270, 84, 200, 14);
								panel.add(lblSuccess);
								panel.revalidate();
								panel.repaint();
							}
						});
						
						btnUpdateHistory.setBounds(450, 400, 150, 23);
						panel.add(btnUpdateHistory);
						
						panel.revalidate();
						panel.repaint();
						answer = null;
						
						
					}
				});
				btnViewMedicalHistory.setBounds(467, 125, 150, 23);
				panel.add(btnViewMedicalHistory);
				
				JButton btnViewTreatmentRecord = new JButton("View/Edit Treatment Record");
				btnViewTreatmentRecord.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						
						String selectedId = (String) list.getSelectedValue();
						int prefixEnd = selectedId.indexOf(" ");
						selectedId = selectedId.substring(0, prefixEnd);
						
						final String editedId = selectedId;
						
						initDoctorPanel();
						
						sendToClient.send("vw_trt_rec " + selectedId);
						
						String answer = "0";
						
						while(answer.equals("0")){
							answer = sendToClient.read();
						}
						
						String medHistoryText = answer.replace("_", " ");
						
						final JTextArea patientHistoryText = new JTextArea(medHistoryText);
						patientHistoryText.setWrapStyleWord(true);
						patientHistoryText.setLineWrap(true);
						patientHistoryText.setEditable(true);
						patientHistoryText.setBounds(255, 79, 330, 300);
						panel.add(patientHistoryText);
						
						JLabel lblNewLabel_2 = new JLabel("Patient Treatment Record");
						lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
						lblNewLabel_2.setBounds(303, 51, 240, 19);
						panel.add(lblNewLabel_2);
						
						JButton btnUpdateHistory = new JButton("Update Record");
						btnUpdateHistory.addMouseListener(new MouseAdapter() {
							@Override
							public void mousePressed(MouseEvent arg0) {
								
								sendToClient.send("edt_trt_rec " + editedId +" "+ patientHistoryText.getText().replace(" ", "_"));
								initDoctorPanel();
								JLabel lblSuccess = new JLabel("TREATMENT RECORD UPDATED!");
								lblSuccess.setBounds(270, 84, 200, 14);
								panel.add(lblSuccess);
								panel.revalidate();
								panel.repaint();
								
							}
						});
						btnUpdateHistory.setBounds(450, 400, 150, 23);
						panel.add(btnUpdateHistory);
						
						panel.revalidate();
						panel.repaint();
						answer = null;
						
					}
				});
				btnViewTreatmentRecord.setBounds(467, 159, 150, 23);
				panel.add(btnViewTreatmentRecord);
				
				answer = null;
				panel.revalidate();
				panel.repaint();
				
			}
		});
		btnNewButton_7.setBounds(10, 57, 200, 23);
		panel.add(btnNewButton_7);
		
		
		JButton btnNewButton_9 = new JButton("View Calender");
		btnNewButton_9.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initDoctorPanel();
				
				JLabel lblNewLabel = new JLabel("Calender");
				lblNewLabel.setBounds(400, 35, 269, 14);
				panel.add(lblNewLabel);
				
				JTextPane txtpnCalender = new JTextPane();
				txtpnCalender.setEditable(false);
				txtpnCalender.setBounds(253, 57, 348, 360);
				panel.add(txtpnCalender);
				
				
				sendToClient.send("vw_cal");
				
				String answer = "0";
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals("0")){
					txtpnCalender.setText(answer.replace("_", " "));
				}
				panel.revalidate();
				panel.repaint();
				answer = null;
				
			}
		});
		btnNewButton_9.setBounds(10, 91, 200, 23);
		panel.add(btnNewButton_9);
		
		JButton btnDocOrders = new JButton("Send Dr's Orders");
		btnDocOrders.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initDoctorPanel();
				
				sendToClient.send("vw_users");
				
				String answer = "0";
				String[] returnArray = null;
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals("0")){
					returnArray = answer.split(" ");
				}
				
				for(int i = 0; i < returnArray.length; i++){
					returnArray[i] = returnArray[i].replace("_", " ");
				}
				
				final String[] valuesArray = returnArray;
				
				final JList list = new JList();
				list.setModel(new AbstractListModel() {
					
					String[] values = valuesArray;
					//values = returnArray;
					public int getSize() {
						return values.length;
					}
					public Object getElementAt(int index) {
						return values[index];
					}
				});
				
				list.setBounds(258, 69, 170, 313);
				panel.add(list);
				
				JLabel lblUserList = new JLabel("USER LIST");
				lblUserList.setHorizontalAlignment(SwingConstants.CENTER);
				lblUserList.setBounds(258, 44, 161, 14);
				panel.add(lblUserList);
				
				JButton btnViewEdit = new JButton("Send Orders");
				btnViewEdit.addMouseListener(new MouseAdapter() {
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						String selectedId = (String) list.getSelectedValue();
						int prefixEnd = selectedId.indexOf(" ");
						selectedId = selectedId.substring(0, prefixEnd);
						
						final String editedId = selectedId;
						
						
							
						initDoctorPanel();
						
						final JTextArea txtrprescription = new JTextArea();
						txtrprescription.setFont(new Font("Tahoma", Font.PLAIN, 11));
						txtrprescription.setLineWrap(true);
						txtrprescription.setWrapStyleWord(true);
						txtrprescription.setText("(Prescription)");
						txtrprescription.setBounds(323, 59, 269, 38);
						panel.add(txtrprescription);
						
						final JTextArea txtrlabWork = new JTextArea();
						txtrlabWork.setFont(new Font("Tahoma", Font.PLAIN, 11));
						txtrlabWork.setWrapStyleWord(true);
						txtrlabWork.setLineWrap(true);
						txtrlabWork.setText("(Lab Work)");
						txtrlabWork.setBounds(323, 108, 269, 58);
						panel.add(txtrlabWork);
						
						final JTextArea txtrfollowUpInstructions = new JTextArea();
						txtrfollowUpInstructions.setFont(new Font("Tahoma", Font.PLAIN, 11));
						txtrfollowUpInstructions.setLineWrap(true);
						txtrfollowUpInstructions.setWrapStyleWord(true);
						txtrfollowUpInstructions.setText("(Follow Up Instructions)");
						txtrfollowUpInstructions.setBounds(323, 177, 269, 93);
						panel.add(txtrfollowUpInstructions);
						
						final JTextArea txtrotherInstructions = new JTextArea();
						txtrotherInstructions.setFont(new Font("Tahoma", Font.PLAIN, 11));
						txtrotherInstructions.setWrapStyleWord(true);
						txtrotherInstructions.setLineWrap(true);
						txtrotherInstructions.setText("(Other Instructions)");
						txtrotherInstructions.setBounds(323, 281, 269, 68);
						panel.add(txtrotherInstructions);
						
						JLabel lblPrescription = new JLabel("Prescription:");
						lblPrescription.setHorizontalAlignment(SwingConstants.RIGHT);
						lblPrescription.setBounds(220, 57, 93, 23);
						panel.add(lblPrescription);
						
						JLabel lblLabWork = new JLabel("Lab Work:");
						lblLabWork.setHorizontalAlignment(SwingConstants.RIGHT);
						lblLabWork.setBounds(220, 110, 93, 14);
						panel.add(lblLabWork);
						
						JLabel lblFollowUpInstructions = new JLabel("Follow Up:");
						lblFollowUpInstructions.setHorizontalAlignment(SwingConstants.RIGHT);
						lblFollowUpInstructions.setBounds(209, 179, 104, 14);
						panel.add(lblFollowUpInstructions);
						
						JLabel lblOther = new JLabel("Other:");
						lblOther.setHorizontalAlignment(SwingConstants.RIGHT);
						lblOther.setBounds(209, 283, 104, 14);
						panel.add(lblOther);
						
						JButton btnSend = new JButton("Send");
						btnSend.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
							@Override
							public void mousePressed(MouseEvent arg0) {
								initDoctorPanel();
								
								txtrprescription.setText("Prescription: " +txtrprescription.getText());
								txtrlabWork.setText("Lab Work: " +txtrlabWork.getText());
								txtrfollowUpInstructions.setText("Follow Up Instructions: " +txtrfollowUpInstructions.getText());
								txtrotherInstructions.setText("Other Instructions: " +txtrotherInstructions.getText());
								
								sendToClient.send("edt_doc_ord "+editedId+" "+txtrprescription.getText().replace(" ","_")+" "+txtrlabWork.getText().replace(" ","_")+" "+txtrfollowUpInstructions.getText().replace(" ","_")+" "+txtrotherInstructions.getText().replace(" ","_"));
								
							
								JLabel lblSuccess = new JLabel("ORDERS SENT!");
								lblSuccess.setBounds(270, 84, 200, 14);
								panel.add(lblSuccess);
							
									
								
								panel.revalidate();
								panel.repaint();
							}
						});
						btnSend.setBounds(412, 383, 89, 23);
						panel.add(btnSend);
						
						panel.revalidate();
						panel.repaint();	
					}
				});
				
				btnViewEdit.setBounds(467, 91, 150, 23);
				panel.add(btnViewEdit);
				
				panel.revalidate();
				panel.repaint();	
				answer = null;
			}
		});
		btnDocOrders.setBounds(10, 125, 200, 23);
		panel.add(btnDocOrders);
		
		JButton btnStats = new JButton("View Statistics");
		btnStats.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initDoctorPanel();
				
				JLabel lblNewLabel = new JLabel("Statistics");
				lblNewLabel.setBounds(400, 35, 269, 14);
				panel.add(lblNewLabel);
				
				JTextPane txtpnCalender = new JTextPane();
				txtpnCalender.setEditable(false);
				txtpnCalender.setBounds(253, 57, 348, 360);
				panel.add(txtpnCalender);
				
				
				sendToClient.send("vw_stats");
				
				String answer = "0";
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals("0")){
					txtpnCalender.setText(answer.replace("_", " "));
				}
				panel.revalidate();
				panel.repaint();
				
			}
		});
		btnStats.setBounds(10, 159, 200, 23);
		panel.add(btnStats);
		
		JButton btnNewButton_12 = new JButton("Log Out");
		btnNewButton_12.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initLoginPanel();
			}
		});
		btnNewButton_12.setBounds(53, 383, 126, 23);
		panel.add(btnNewButton_12);
		
		
		
		panel.revalidate();
		panel.repaint();
		
		
	}
	
	/**
	 * LAUNCH NURSE PANEL
	 */
	
	public void initNursePanel(){
				
			panel.removeAll();
			panel.setLayout(null);
				
			JLabel lblNewLabel = new JLabel("Welcome Nurse!");
			lblNewLabel.setBounds(250, 11, 269, 14);
			panel.add(lblNewLabel);
			
			JButton btnNewButton_7 = new JButton("View/Edit Patient Info");			
			btnNewButton_7.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
				@Override
				public void mousePressed(MouseEvent arg0) {
					
					initNursePanel();
					
					sendToClient.send("vw_users");
					
					String answer = "0";
					String[] returnArray = null;
					
					while(answer.equals("0")){
						answer = sendToClient.read();
					}
					
					if(!answer.equals("0")){
						returnArray = answer.split(" ");
					}
					
					for(int i = 0; i < returnArray.length; i++){
						returnArray[i] = returnArray[i].replace("_", " ");
					}
					
					final String[] valuesArray = returnArray;
					
					final JList list = new JList();
					list.setModel(new AbstractListModel() {
						
						String[] values = valuesArray;
						//values = returnArray;
						public int getSize() {
							return values.length;
						}
						public Object getElementAt(int index) {
							return values[index];
						}
					});
					
					list.setBounds(258, 69, 170, 313);
					panel.add(list);
					
					JLabel lblUserList = new JLabel("USER LIST");
					lblUserList.setHorizontalAlignment(SwingConstants.CENTER);
					lblUserList.setBounds(258, 44, 161, 14);
					panel.add(lblUserList);
					
					JButton btnViewEdit = new JButton("View/edit");
					btnViewEdit.addMouseListener(new MouseAdapter() {
						@Override
						public void mousePressed(MouseEvent arg0) {
							
							String selectedId = (String) list.getSelectedValue();
							int prefixEnd = selectedId.indexOf(" ");
							selectedId = selectedId.substring(0, prefixEnd);
							
							final String editedId = selectedId;
							
							
							sendToClient.send("vw_bi" + " " + editedId);
							
							String answer = "0";
							while(answer.equals("0")){
								answer = sendToClient.read();
							}
							
							if(!answer.equals(-1)){
								
							}
								
							initNursePanel();
							
							String returnArray[] = answer.split(" ");
							String firstName = returnArray[0];
							String lastName = returnArray[1];
							String dateOfBirth = returnArray[2];
							String age = returnArray[3];
							String height = returnArray[4];
							String weight = returnArray[5];
							
							JLabel lblFirstName = new JLabel("First Name:");
							lblFirstName.setBounds(270, 84, 70, 14);
							panel.add(lblFirstName);
							
							JLabel lblLastName_1 = new JLabel("Last Name:");
							lblLastName_1.setBounds(270, 118, 70, 14);
							panel.add(lblLastName_1);
							
							JLabel lblDateOfBirth = new JLabel("Date of Birth:");
							lblDateOfBirth.setBounds(270, 152, 90, 14);
							panel.add(lblDateOfBirth);
							
							JLabel lblAge = new JLabel("Age:");
							lblAge.setBounds(270, 186, 70, 14);
							panel.add(lblAge);
							
							JLabel lblHeight = new JLabel("Height:");
							lblHeight.setBounds(270, 220, 70, 14);
							panel.add(lblHeight);
							
							JLabel lblWeight = new JLabel("Weight:");
							lblWeight.setBounds(270, 251, 70, 14);
							panel.add(lblWeight);
							
							txtFirstName = new JTextField();
							txtFirstName.setText(firstName);
							txtFirstName.setBounds(361, 80, 203, 20);
							panel.add(txtFirstName);
							txtFirstName.setColumns(10);
							
							txtLastName_1 = new JTextField();
							txtLastName_1.setText(lastName);
							txtLastName_1.setBounds(361, 114, 203, 20);
							panel.add(txtLastName_1);
							txtLastName_1.setColumns(10);
							
							txtDateOfBirth = new JTextField();
							txtDateOfBirth.setText(dateOfBirth);
							txtDateOfBirth.setBounds(361, 148, 102, 20);
							panel.add(txtDateOfBirth);
							txtDateOfBirth.setColumns(10);
							
							txtAge = new JTextField();
							txtAge.setText(age);
							txtAge.setBounds(361, 182, 102, 20);
							panel.add(txtAge);
							txtAge.setColumns(10);
							
							txtHeight = new JTextField();
							txtHeight.setText(height);
							txtHeight.setBounds(361, 216, 102, 20);
							panel.add(txtHeight);
							txtHeight.setColumns(10);
							
							txtWeight = new JTextField();
							txtWeight.setText(weight);
							txtWeight.setBounds(361, 247, 102, 20);
							panel.add(txtWeight);
							txtWeight.setColumns(10);
							
							JButton btnNewButton_13 = new JButton("Update");
							
							btnNewButton_13.addMouseListener(new MouseAdapter() {
								@Override
								public void mousePressed(MouseEvent arg0) {
									
									String firstName = txtFirstName.getText().replace(" ", "_");
									String lastName = txtLastName_1.getText().replace(" ", "_");
									String fullName = firstName+ " " + lastName;
									String dateOfBirth = txtDateOfBirth.getText();
									String age = txtAge.getText();
									String height = txtHeight.getText();
									String weight = txtWeight.getText();
									
									dateOfBirth = dateOfBirth.replace(" ", "_");
									age = age.replace(" ", "_");
									height = height.replace(" ", "_");
									weight = weight.replace(" ", "_");
					
									sendToClient.send("edt_ptnt" + " " + editedId+" "+fullName+" "+dateOfBirth+ " " +age+" "+height+" "+weight);
									
									String answer = "no";
									
									while(answer.equals("no")){
										answer = sendToClient.read();
									}
									
									if(answer.equals("0")){
										initNursePanel();
										System.out.print("SUCCESSFUL UPDATE");
										
										JLabel lblSuccess = new JLabel("INFORMATION UPDATED!");
										lblSuccess.setBounds(270, 84, 200, 14);
										panel.add(lblSuccess);
										panel.revalidate();
										panel.repaint();
									}
								}
							});
							btnNewButton_13.setBounds(353, 300, 89, 23);
							panel.add(btnNewButton_13);
							
							panel.revalidate();
							panel.repaint();
							
							
							
							
						}
					});

					btnViewEdit.setBounds(467, 91, 150, 23);
					panel.add(btnViewEdit);
					
					panel.revalidate();
					panel.repaint();

					
				}
			});
			btnNewButton_7.setBounds(10, 57, 200, 23);
			panel.add(btnNewButton_7);
			
			JButton btnNewButton_8 = new JButton("View Appointment Requests");
			btnNewButton_8.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
				@Override
				public void mousePressed(MouseEvent arg0) {
					
					initNursePanel();
					
					sendToClient.send("vw_pending");
					
					String answer = "0";
					String[] returnArray = null;
					
					
					while((answer.equals("0")) || (answer.equals("0"))){
						answer = sendToClient.read();
					}
					
					String[] noRequests = new String[1];
					noRequests[0] = "No Requested Appointments.";
						
					
					if(!answer.equals("")){
						returnArray = answer.split("\n");
						String splittedAppointments[] = null;
						String[] userIdArray = new String[returnArray.length];
						for(int i = 0; i < returnArray.length; i++){
							splittedAppointments = returnArray[i].split("\t");
							userIdArray[i] = "ID# " + splittedAppointments[7];
						}
						noRequests = userIdArray;
					}
					
					final String[] valuesArray = noRequests;
					
					final JList list = new JList();
					list.setModel(new AbstractListModel() {
						
						String[] values = valuesArray;
						//values = returnArray;
						public int getSize() {
							return values.length;
						}
						public Object getElementAt(int index) {
							return values[index];
						}
					});
					
					list.setBounds(258, 69, 170, 313);
					panel.add(list);
					
					JLabel lblUserList = new JLabel("Appointment Requests");
					lblUserList.setHorizontalAlignment(SwingConstants.CENTER);
					lblUserList.setBounds(258, 44, 161, 14);
					panel.add(lblUserList);
					
					JButton btnView = new JButton("View");
					btnView.addMouseListener(new MouseAdapter() {
						@Override
						public void mousePressed(MouseEvent arg0) {
							
							//returnArray[list.getSelectedIndex()];
							
							String selectedId = (String) list.getSelectedValue();
							selectedId = selectedId.substring(4, selectedId.length());
							
							final String editedId = selectedId;
							
							
							initNursePanel();
															
							sendToClient.send("vw_appt "+ editedId);
							
							String answer = "0";
							
							while(answer.equals("0")){
								answer = sendToClient.read();
							}
							if(answer.equals("-1")){
								answer = "No Requested Appointments";
							}
							
							String appointmentRequests = answer;
							
							JTextArea patientHistoryText = new JTextArea(appointmentRequests);
							patientHistoryText.setWrapStyleWord(true);
							patientHistoryText.setLineWrap(true);
							patientHistoryText.setEditable(false);
							patientHistoryText.setBounds(255, 79, 332, 280);
							panel.add(patientHistoryText);
							
							JLabel lblNewLabel_2 = new JLabel("Appointment Requests");
							lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
							lblNewLabel_2.setBounds(303, 51, 242, 19);
							panel.add(lblNewLabel_2);
							
							JButton btnApprove = new JButton("Approve");
							btnApprove.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
								@Override
								public void mousePressed(MouseEvent arg0) {
									
									sendToClient.send("proc_appt "+ editedId + " 1");
									initNursePanel();
									JLabel lblSuccess = new JLabel("APPOINTMENT APPROVED");
									lblSuccess.setBounds(270, 84, 200, 14);
									panel.add(lblSuccess);
									panel.revalidate();
									panel.repaint();
									
								}
							});
							btnApprove.setBounds(270, 383, 126, 23);
							panel.add(btnApprove);
							
							JButton btnDeny = new JButton("Deny");
							btnDeny.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
								@Override
								public void mousePressed(MouseEvent arg0) {
									
									sendToClient.send("proc_appt "+ editedId + " 0");
									initNursePanel();
									JLabel lblSuccess = new JLabel("APPOINTMENT DENIED");
									lblSuccess.setBounds(270, 84, 200, 14);
									panel.add(lblSuccess);
									panel.revalidate();
									panel.repaint();
								}
							});
							btnDeny.setBounds(410, 383, 126, 23);
							panel.add(btnDeny);
							
							panel.revalidate();
							panel.repaint();
							
						}
						
					});
					
				
					btnView.setBounds(467, 91, 150, 23);
					panel.add(btnView);
					
					panel.revalidate();
					panel.repaint();

					
				}
			});
			btnNewButton_8.setBounds(10, 91, 200, 23);
			panel.add(btnNewButton_8);
			
			JButton btnNewButton_9 = new JButton("View Calender");
			btnNewButton_9.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
				@Override
				public void mousePressed(MouseEvent arg0) {
					initNursePanel();
					
					JLabel lblNewLabel = new JLabel("Calender");
					lblNewLabel.setBounds(400, 35, 269, 14);
					panel.add(lblNewLabel);
					
					JTextPane txtpnCalender = new JTextPane();
					txtpnCalender.setEditable(false);
					txtpnCalender.setBounds(253, 57, 348, 360);
					panel.add(txtpnCalender);
					
					
					sendToClient.send("vw_cal");
					
					String answer = "0";
					
					while(answer.equals("0")){
						answer = sendToClient.read();
					}
					
					if(!answer.equals("0")){
						txtpnCalender.setText(answer.replace("_", " "));
					}
					panel.revalidate();
					panel.repaint();
					
				}
			});
			btnNewButton_9.setBounds(10, 125, 200, 23);
			panel.add(btnNewButton_9);
			
			JButton btnNewButton_10 = new JButton("View Statistics");
			btnNewButton_10.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
				@Override
				public void mousePressed(MouseEvent arg0) {
					initNursePanel();
					
					JLabel lblNewLabel = new JLabel("Statistics");
					lblNewLabel.setBounds(400, 35, 269, 14);
					panel.add(lblNewLabel);
					
					JTextPane txtpnCalender = new JTextPane();
					txtpnCalender.setEditable(false);
					txtpnCalender.setBounds(253, 57, 348, 360);
					panel.add(txtpnCalender);
					
					
					sendToClient.send("vw_stats");
					
					String answer = "0";
					
					while(answer.equals("0")){
						answer = sendToClient.read();
					}
					
					if(!answer.equals("0")){
						txtpnCalender.setText(answer.replace("_", " "));
					}
					panel.revalidate();
					panel.repaint();
					
				}
			});
			btnNewButton_10.setBounds(10, 159, 200, 23);
			panel.add(btnNewButton_10);
			
			JButton btnInvoice = new JButton("Send Invoice");
			btnInvoice.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
				@Override
				public void mousePressed(MouseEvent arg0) {
					
					initNursePanel();
					
					sendToClient.send("vw_users");
					
					String answer = "0";
					String[] returnArray = null;
					
					while(answer.equals("0")){
						answer = sendToClient.read();
					}
					
					if(!answer.equals("0")){
						returnArray = answer.split(" ");
					}
					
					for(int i = 0; i < returnArray.length; i++){
						returnArray[i] = returnArray[i].replace("_", " ");
					}
					
					final String[] valuesArray = returnArray;
					
					final JList list = new JList();
					list.setModel(new AbstractListModel() {
						
						String[] values = valuesArray;
						//values = returnArray;
						public int getSize() {
							return values.length;
						}
						public Object getElementAt(int index) {
							return values[index];
						}
					});
					
					list.setBounds(258, 69, 170, 313);
					panel.add(list);
					
					JLabel lblUserList = new JLabel("USER LIST");
					lblUserList.setHorizontalAlignment(SwingConstants.CENTER);
					lblUserList.setBounds(258, 44, 161, 14);
					panel.add(lblUserList);
					
					JButton btnCreate = new JButton("Send Invoice");
					btnCreate.addMouseListener(new MouseAdapter() {
						@Override
						public void mousePressed(MouseEvent arg0) {
							
							String selectedId = (String) list.getSelectedValue();
							int prefixEnd = selectedId.indexOf(" ");
							selectedId = selectedId.substring(0, prefixEnd);
							
							final String editedId = selectedId;						
								
							initNursePanel();
							

							String reason = "(reason)";
							String price = "(price)";

							
							JLabel lblReason = new JLabel("Reason:");
							lblReason.setBounds(270, 84, 70, 14);
							panel.add(lblReason);
							
							JLabel lblPrice = new JLabel("Price:");
							lblPrice.setBounds(270, 118, 70, 14);
							panel.add(lblPrice);
							
							final JTextField txtReason = new JTextField();
							txtReason.setText(reason);
							txtReason.setBounds(361, 80, 203, 20);
							panel.add(txtReason);
							txtReason.setColumns(10);
							
							final JTextField txtPrice = new JTextField();
							txtPrice.setText(price);
							txtPrice.setBounds(361, 114, 203, 20);
							panel.add(txtPrice);
							txtPrice.setColumns(10);
							
							JButton btnSend = new JButton("Send");
							btnSend.addMouseListener(new MouseAdapter() {
								@Override
								public void mousePressed(MouseEvent arg0) {
									
									sendToClient.send("edt_invoice " + editedId +" "+txtReason.getText().replace(" ", "_")+" "+ txtPrice.getText().replace(" ", "_"));
									
									initNursePanel();
									
									JLabel lblSuccess = new JLabel("INVOICE SENT");
									lblSuccess.setBounds(270, 84, 200, 14);
									panel.add(lblSuccess);
									panel.revalidate();
									panel.repaint();
									
								}
							});
							btnSend.setBounds(353, 200, 89, 23);
							panel.add(btnSend);
							
							panel.revalidate();
							panel.repaint();
	
						}
					});
					btnCreate.setBounds(450, 100, 150, 23);
					panel.add(btnCreate);
					panel.revalidate();
					panel.repaint();
				}
			});
			btnInvoice.setBounds(10, 193, 200, 23);
			panel.add(btnInvoice);
			
			JButton btnNewButton_12 = new JButton("Log Out");
			btnNewButton_12.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
				@Override
				public void mousePressed(MouseEvent arg0) {
					initLoginPanel();
				}
			});
			btnNewButton_12.setBounds(53, 383, 126, 23);
			panel.add(btnNewButton_12);
			panel.revalidate();
			panel.repaint();
			
		}

/**
 * LAUNCH ADMIN PANEL
 */

	public void initAdminPanel(){
		
		panel.removeAll();
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Welcome Administrator!");
		lblNewLabel.setBounds(150, 11, 269, 14);
		panel.add(lblNewLabel);
		
		JButton btnNewButton_7 = new JButton("Edit User Accounts");
		btnNewButton_7.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initAdminPanel();
				sendToClient.send("vw_users");
				
				String answer = "0";
				String[] returnArray = null;
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals("0")){
					returnArray = answer.split(" ");
				}
				
				for(int i = 0; i < returnArray.length; i++){
					returnArray[i] = returnArray[i].replace("_", " ");
				}
				
				final String[] valuesArray = returnArray;
				
				final JList list = new JList();
				list.setModel(new AbstractListModel() {
					
					String[] values = valuesArray;
					//values = returnArray;
					public int getSize() {
						return values.length;
					}
					public Object getElementAt(int index) {
						return values[index];
					}
				});
				
				list.setBounds(258, 69, 170, 313);
				panel.add(list);
				
				JLabel lblUserList = new JLabel("USER LIST");
				lblUserList.setHorizontalAlignment(SwingConstants.CENTER);
				lblUserList.setBounds(258, 44, 161, 14);
				panel.add(lblUserList);
				
				JButton btnDeleteUser = new JButton("Delete User");
				btnDeleteUser.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						String selectedId = (String) list.getSelectedValue();
						int prefixEnd = selectedId.indexOf(" ");
						selectedId = selectedId.substring(0, prefixEnd);
						
						sendToClient.send("del_acct " + selectedId);
						
						sendToClient.send("vw_users");
						
						String answer = "0";
						String[] returnArray = null;
						
						while(answer.equals("0")){
							if(sendToClient.read() != "0"){
								answer = sendToClient.read();
							}
						}
						
						if(!answer.equals("0")){
							returnArray = answer.split(" ");
							
							//txtpnCalender.setText(answer.replace("_", " "));
						}
						
						for(int i = 0; i < returnArray.length; i++){
							returnArray[i] = returnArray[i].replace("_", " ");
						}
						
						final String[] valuesArray = returnArray;
						
						//final JList list = new JList();
						list.setModel(new AbstractListModel() {
							
							String[] values = valuesArray;
							//values = returnArray;
							public int getSize() {
								return values.length;
							}
							public Object getElementAt(int index) {
								return values[index];
							}
						});
						
						list.setBounds(258, 69, 170, 313);
						panel.add(list);
						
						panel.revalidate();
						panel.repaint();
						
						
						
						
					}
				});
				btnDeleteUser.setBounds(467, 91, 130, 23);
				panel.add(btnDeleteUser);
				
				JButton btnUnsuspendUser = new JButton("Unsuspend User");
				btnUnsuspendUser.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						String selectedId = (String) list.getSelectedValue();
						int prefixEnd = selectedId.indexOf(" ");
						selectedId = selectedId.substring(0, prefixEnd);
						
						sendToClient.send("enbl_acct " + selectedId);
						
						sendToClient.send("vw_users");
						
						String answer = "0";
						String[] returnArray = null;
						
						while(answer.equals("0")){
							if(sendToClient.read() != "0"){
								answer = sendToClient.read();
							}
						}
						
						if(!answer.equals("0")){
							returnArray = answer.split(" ");
							
							//txtpnCalender.setText(answer.replace("_", " "));
						}
						
						for(int i = 0; i < returnArray.length; i++){
							returnArray[i] = returnArray[i].replace("_", " ");
						}
						
						final String[] valuesArray = returnArray;
						
						//final JList list = new JList();
						list.setModel(new AbstractListModel() {
							
							String[] values = valuesArray;
							//values = returnArray;
							public int getSize() {
								return values.length;
							}
							public Object getElementAt(int index) {
								return values[index];
							}
						});
						
						list.setBounds(258, 69, 170, 313);
						panel.add(list);
						
						panel.revalidate();
						panel.repaint();
						
						
						
						
					}
				});
				btnUnsuspendUser.setBounds(467, 125, 130, 23);
				panel.add(btnUnsuspendUser);
				
				JButton btnSuspendUser = new JButton("Suspend User");
				btnSuspendUser.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						String selectedId = (String) list.getSelectedValue();
						int prefixEnd = selectedId.indexOf(" ");
						selectedId = selectedId.substring(0, prefixEnd);
						
						sendToClient.send("sspnd_acct " + selectedId);
						
						sendToClient.send("vw_users");
						
						String answer = "0";
						String[] returnArray = null;
						
						while(answer.equals("0")){
							if(sendToClient.read() != "0"){
								answer = sendToClient.read();
							}
						}
						
						if(!answer.equals("0")){
							returnArray = answer.split(" ");
							
							//txtpnCalender.setText(answer.replace("_", " "));
						}
						
						for(int i = 0; i < returnArray.length; i++){
							returnArray[i] = returnArray[i].replace("_", " ");
						}
						
						final String[] valuesArray = returnArray;
						
						//final JList list = new JList();
						list.setModel(new AbstractListModel() {
							
							String[] values = valuesArray;
							//values = returnArray;
							public int getSize() {
								return values.length;
							}
							public Object getElementAt(int index) {
								return values[index];
							}
						});
						
						list.setBounds(258, 69, 170, 313);
						panel.add(list);
						
						panel.revalidate();
						panel.repaint();
						
					}
				});
				
				btnSuspendUser.setBounds(467, 159, 130, 23);
				panel.add(btnSuspendUser);
				
				JButton btnAddUser = new JButton("Add User");
				btnAddUser.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
					@Override
					public void mousePressed(MouseEvent arg0) {
						
						initAdminPanel();
				
						JLabel lblNewUserSignup = new JLabel("Create Account");
						lblNewUserSignup.setBounds(340, 11, 130, 40);
						panel.add(lblNewUserSignup);
						
						final JTextField txtUsername = new JTextField();
						txtUsername.setText("Username");
						txtUsername.setBounds(340, 62, 142, 20);
						panel.add(txtUsername);
						txtUsername.setColumns(10);
						
						final JTextField txtPassword = new JTextField();
						txtPassword.setText("Password");
						txtPassword.setBounds(340, 93, 142, 20);
						panel.add(txtPassword);
						txtPassword.setColumns(10);
						
						final JTextField txtFullname = new JTextField();
						txtFullname.setText("First Name");
						txtFullname.setBounds(340, 146, 142, 20);
						panel.add(txtFullname);
						txtFullname.setColumns(10);
						
						final JTextField txtPhoneNumber = new JTextField();
						txtPhoneNumber.setText("Phone Number");
						txtPhoneNumber.setBounds(340, 221, 142, 20);
						panel.add(txtPhoneNumber);
						txtPhoneNumber.setColumns(10);
						
						final JTextField txtLastName = new JTextField();
						txtLastName.setText("Last Name");
						txtLastName.setColumns(10);
						txtLastName.setBounds(340, 181, 142, 20);
						panel.add(txtLastName);
						
						final JComboBox userType = new JComboBox();
						userType.setModel(new DefaultComboBoxModel(new String[] {"Patient", "Nurse", "Doctor"}));
						userType.setBounds(345, 277, 100, 22);
						panel.add(userType);
						
						JButton btnCreateAccount = new JButton("Create Account");
						
						btnCreateAccount.addMouseListener(new MouseAdapter() {
							@Override
							public void mousePressed(MouseEvent arg0) {
								
								//INSERT NEW USER LOGIN BUTTON ACTION CODE HERE
								
								String username = txtUsername.getText();
								username = username.replace(" ", "_");
								String password = txtPassword.getText();
								password = password.replace(" ", "_");
								String firstName = txtFullname.getText();
								firstName = firstName.replace(" ", "_");
								String lastName = txtLastName.getText();
								lastName = lastName.replace(" ", "_");
								String phoneNumber = txtPhoneNumber.getText();
								phoneNumber = phoneNumber.replace(" ", "_");
								
								sendToClient.send("newusr "+username+" "+password+" "+firstName+" "+lastName+" "+phoneNumber+ " " + (userType.getSelectedIndex()+""));
								System.out.print("newusr "+username+" "+password+" "+firstName+" "+lastName+" "+phoneNumber+ " " + (userType.getSelectedIndex()+""));
								
								String answer = "0";
								while(answer.equals("0")){
									answer = sendToClient.read();
								}
								
								if(!answer.equals(-1)){
									initAdminPanel();
									JLabel lblSuccess = new JLabel("User Added!");
									lblSuccess.setBounds(258, 149, 133, 14);
									panel.add(lblSuccess);
								}
								
								
							}
						});
						btnCreateAccount.setBounds(245, 380, 142, 28);
						panel.add(btnCreateAccount);
						
						JLabel lblFullNamefirst = new JLabel("First Name:");
						lblFullNamefirst.setBounds(258, 149, 133, 14);
						panel.add(lblFullNamefirst);
						
						JLabel lblContactPhoneNumber = new JLabel("User Type:");
						lblContactPhoneNumber.setBounds(300, 224, 133, 14);
						panel.add(lblContactPhoneNumber);
						
						JLabel lblUsername = new JLabel("Username:");
						lblUsername.setBounds(233, 65, 97, 14);
						panel.add(lblUsername);
						
						JLabel lblPassword = new JLabel("Password:");
						lblPassword.setBounds(233, 96, 97, 14);
						panel.add(lblPassword);
						
						JLabel lblLastName = new JLabel("Last Name:");
						lblLastName.setBounds(257, 184, 133, 14);
						panel.add(lblLastName);
						
						JLabel lblPhone = new JLabel("Phone #:");
						lblPhone.setBounds(257, 215, 133, 14);
						panel.add(lblPhone);
						
						JLabel lblTypeOfUser = new JLabel("Type of User:");
						lblContactPhoneNumber.setBounds(209, 277, 133, 14);
						panel.add(lblContactPhoneNumber);
						
						
						panel.revalidate();
						panel.repaint();	
				
					}
				});
				btnAddUser.setBounds(467, 193, 130, 23);
				panel.add(btnAddUser);
				
				panel.revalidate();
				panel.repaint();
				
			}
		});
		btnNewButton_7.setBounds(10, 57, 200, 23);
		panel.add(btnNewButton_7);
		
		JButton btnNewButton_9 = new JButton("View Calender");
		btnNewButton_9.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initAdminPanel();
				
				JLabel lblNewLabel = new JLabel("Calender");
				lblNewLabel.setBounds(400, 35, 269, 14);
				panel.add(lblNewLabel);
				
				JTextPane txtpnCalender = new JTextPane();
				txtpnCalender.setEditable(false);
				txtpnCalender.setBounds(253, 57, 348, 360);
				panel.add(txtpnCalender);
				
				
				sendToClient.send("vw_cal");
				
				String answer = "0";
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals("0")){
					txtpnCalender.setText(answer.replace("_", " "));
				}
				panel.revalidate();
				panel.repaint();
			}
		});
		btnNewButton_9.setBounds(10, 91, 200, 23);
		panel.add(btnNewButton_9);
		
		JButton btnStats = new JButton("View Statistics");
		btnStats.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initAdminPanel();
				
				JLabel lblNewLabel = new JLabel("Statistics");
				lblNewLabel.setBounds(400, 35, 269, 14);
				panel.add(lblNewLabel);
				
				JTextPane txtpnCalender = new JTextPane();
				txtpnCalender.setEditable(false);
				txtpnCalender.setBounds(253, 57, 348, 360);
				panel.add(txtpnCalender);
				
				
				sendToClient.send("vw_stats");
				
				String answer = "0";
				
				while(answer.equals("0")){
					answer = sendToClient.read();
				}
				
				if(!answer.equals("0")){
					txtpnCalender.setText(answer.replace("_", " "));
				}
				panel.revalidate();
				panel.repaint();
				
			}
		});
		btnStats.setBounds(10, 125, 200, 23);
		panel.add(btnStats);
		
		
		JButton btnNewButton_12 = new JButton("Log Out");
		btnNewButton_12.addMouseListener(new MouseAdapter() {  //ACTION WHEN LOGOUT PRESSED
			@Override
			public void mousePressed(MouseEvent arg0) {
				initLoginPanel();
			}
		});
		btnNewButton_12.setBounds(53, 383, 126, 23);
		panel.add(btnNewButton_12);
		
		panel.revalidate();
		panel.repaint();
	}
}

